<?php
namespace app\api\service;
use think\Controller;
use think\Db;

class MemberWallet extends Controller {
    static protected $err_code = 0;

    // 获取钱包首页数据
    static public function wallet_index($param) {
        if(!isset($param['member_id']) || !isset($param['type'])){
            return ['data'=>'','code'=>400001,'msg'=> 'FAULT'];
        }
        try {
            // 获取实名认证信息
            $models = ['member', 'repair', 'dealer', 'partner'];
            $model = $models[$param['type']];
            if ($model) {
                if ($param['type'] == 0) {
                    $map['id'] = $param['member_id'];
                } else {
                    $map['member_id'] = $param['member_id'];
                }
                // 用户余额
                $money = db($model)->where($map)->value('money');
            } else {
                self::$err_code = 400078;
                throw new \Exception('FAULT');
            }
            
            // 获取用户银行卡列表
            $bank_num = db('member_fund_account')->where('member_id', $param['member_id'])->count();

            $data =[
                'money' => $money,
                'bank_num' => $bank_num
            ];

            return ['code' => 200, 'data' => $data, 'msg' =>'success'];
        }catch (\Exception $e) {
            return ['code'=>self::$err_code, 'msg'=> $e->getMessage()];
        }
    }
}
